ROOT_DIR=$(cd ..;pwd)
BUILD_OUTPUTFILE="build-web"
JDREACT_MODULE=$1
output_buildfile () {
  cd $ROOT_DIR
}

doErrorExit () {
  cd $ROOT_DIR
#  cd web
  echo ">>>>>> remove BUILD_FILE"
  rm -rf $BUILD_OUTPUTFILE
  exit 1
}

doExit () {
  output_buildfile
  exit 0
}

cd $ROOT_DIR

zip -r $BUILD_OUTPUTFILE $BUILD_OUTPUTFILE
if [[ "$?" != "0" ]]; then
  echo ">>>>>> zip faild!!"
  exit 1
else
  echo ">>>>>> zip success!!"
fi

# upload zip to clound
echo ">>>>>> start to upload..."
cd node_modules/@jdreact/jdreact-core-scripts/bin/
./cloudUploader-new.sh "$JDREACT_MODULE" "$ROOT_DIR/$BUILD_OUTPUTFILE.zip"
cd -

doExit